﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PacketBuilder;
using System.ComponentModel;

namespace PacketBuilder
{
    /// <summary>
    /// Interaction logic for OptionsViewUDP.xaml
    /// </summary>
    public partial class OptionsViewUDP : UserControl, INotifyPropertyChanged
    {
        private static readonly int headerLength = 8;
        private string messageLength;
        public string MessageLength
        {
            get { return messageLength; }
            set
            {
                messageLength = value;
                OnPropertyChanged("messageLength");
            }
        }
        public OptionsViewUDP()
        {
            InitializeComponent();
        }
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            var senderTextBox = sender as TextBox;
            if (null != senderTextBox.Tag)
            {
                if (true == senderTextBox.Tag.Equals("udp-body"))
                {
                    MessageLength = (headerLength + senderTextBox.Text.Length).ToString();
                }
            }
            MainWindow.TextBoxChanged(sender, e);
        }

        #region Implementation of INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
}
